package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ShoppingCartMapper {
    //根据用户id或dish id或setmeal id 查找是否有此菜品或套餐
    ShoppingCart findUidDidOrSid(ShoppingCart shoppingCart);
    //添加购物车
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);
    //更新购物车
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void update(ShoppingCart shoppingCartOne);
    //根据登入者查询购物车
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findCartByUserId(Long userId);


    //删除当前用户的购物车数据
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void clean(Long userId);
    //通过菜品id查询菜品信息
    ShoppingCart findDishByDishId(Long dishId, Long userId);
    //修改购物车菜品
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNum(ShoppingCart shoppingCart);
    /*删除菜品*/
    @Delete("delete from shopping_cart where dish_id=#{dishId} and user_id=#{userId}")
    void deleteDish(Long dishId, Long userId);

}
